// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;

namespace SnapObjects.Data
{
    internal sealed class DynamicModel<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> : DynamicModelBase
    {
        private T0 _field0;
        private T1 _field1;
        private T2 _field2;
        private T3 _field3;
        private T4 _field4;
        private T5 _field5;
        private T6 _field6;
        private T7 _field7;
        private T8 _field8;
        private T9 _field9;
        public DynamicModel() : base(10)
        {

        }

        public DynamicModel(object[] values) : base(values, 10)
        {

        }

        protected override object Getter(int index)
        {
            switch (index)
            {
                case 0:
                    return _field0;
                case 1:
                    return _field1;
                case 2:
                    return _field2;
                case 3:
                    return _field3;
                case 4:
                    return _field4;
                case 5:
                    return _field5;
                case 6:
                    return _field6;
                case 7:
                    return _field7;
                case 8:
                    return _field8;
                case 9:
                    return _field9;
                default:
                    throw new IndexOutOfRangeException();
            }
        }

        protected override void Setter(int index, object value)
        {
            switch (index)
            {
                case 0:
                    _field0 = this.GetCompatibleValue<T0>(value);
                    break;
                case 1:
                    _field1 = this.GetCompatibleValue<T1>(value);
                    break;
                case 2:
                    _field2 = this.GetCompatibleValue<T2>(value);
                    break;
                case 3:
                    _field3 = this.GetCompatibleValue<T3>(value);
                    break;
                case 4:
                    _field4 = this.GetCompatibleValue<T4>(value);
                    break;
                case 5:
                    _field5 = this.GetCompatibleValue<T5>(value);
                    break;
                case 6:
                    _field6 = this.GetCompatibleValue<T6>(value);
                    break;
                case 7:
                    _field7 = this.GetCompatibleValue<T7>(value);
                    break;
                case 8:
                    _field8 = this.GetCompatibleValue<T8>(value);
                    break;
                case 9:
                    _field9 = this.GetCompatibleValue<T9>(value);
                    break;
                default:
                    throw new IndexOutOfRangeException();
            }
        }

        protected override void InitialTypeInfo()
        {
            var list = new List<Type>()
            {
                typeof(T0),
                typeof(T1),
                typeof(T2),
                typeof(T3),
                typeof(T4),
                typeof(T5),
                typeof(T6),
                typeof(T7),
                typeof(T8),
                typeof(T9)
            };

            this.SetTypeInfo(list);
        }
    }
}
